<template>
<div style="padding: 20px" >
  <div>
    <div style="margin-bottom: 20px">
      <community-select-second ref="communitySelect" @callBack="callBack"></community-select-second>
      <Button type="primary" style="margin-right: 10px" @click="findInit">查询</Button>
    </div>
    <!--      </Col>-->
    <!--    </Row>-->
  </div>
  <Table border :columns="tableColumns" :data="tableData" :loading="tableLoading">
    <template slot-scope="{ row, index }" slot="type">
      <span v-show="row.type === '1'">学校</span>
      <span v-show="row.type === '2'">监狱</span>
    </template>
  </Table>
  <Row type="flex" justify="end" class="page_style">
    <Page :current="params.pageNo" :total="params.totalRecord" show-sizer :page-size="params.pageSize" show-elevator
          @on-change="pageAction" @on-page-size-change="pageSizeChange"/>
  </Row>
</div>
</template>

<script>
import { findSchoolInfoTJList } from '../../api/eventlist'
import CommunitySelectSecond from '../../components/community-select-second'

export default {
  name: 'index',
  components: { CommunitySelectSecond },
  data () {
    return {
      severUserInfo: {},
      tableLoading: false,
      params: {
        pageNo: 1,
        pageSize: 10,
        totalRecord: 0
      },
      tableColumns: [
        {
          title: '区/县',
          key: 'area_name',
          align: 'center'
        },
        {
          title: '街道/乡镇',
          key: 'street_name',
          align: 'center'
        },
        {
          title: '社区/村',
          key: 'community_name',
          align: 'center'
        },
        // {
        //   title: '名称',
        //   key: 'name',
        //   align: 'center'
        // },
        // {
        //   title: '类型',
        //   slot: 'type',
        //   align: 'center'
        // },
        {
          title: '录入人数',
          key: 'people_num',
          align: 'center'
        }
      ],
      tableData: []
    }
  },
  methods: {
    callBack (e) {
      console.log('callBack', e)
      this.params.area_id = e.area_id
      this.params.street_id = e.street_id
      this.params.community_id = e.community_id
    },
    findInit () {
      this.params.pageNo = 1
      this.init()
    },
    init () {
      findSchoolInfoTJList(this.params).then(ret => {
        if (ret.data.errcode === 0) {
          this.tableData = ret.data.data.results
          this.params.totalRecord = ret.data.data.totalRecord
          this.tableLoading = false
        } else {
          this.$Notice.error({ title: '查询失败！', desc: ret.data.errmsg })
        }
      })
    },
    pageAction (page) {
      this.params.pageNo = page
      this.init()
    },
    // 改变条数
    pageSizeChange (e) {
      this.params.pageSize = e
      this.init()
    }
  },
  mounted () {
    this.severUserInfo = this.$store.state.user.severUserInfo
    this.init()
    this.$refs.communitySelect.init(this.severUserInfo)
  }
}
</script>

<style scoped>
.page_style {
  margin: 20px 5px;
}
</style>
